// OK
#include "output.h"
#include "panic.h"
#include "func.h"

char buf[1024];
void test_getdents(void){
    TEST_START(__func__);
    int fd, nread;

    struct linux_dirent64 *dirp64 = (struct linux_dirent64*) buf;
    fd = open(".", O_RDONLY);
    printf("open fd: %d\n", fd);
	nread = getdents(fd, dirp64, 1024);
	printf("getdents nread:%d\n", nread);
	assert(nread != -1);
	printf("getdents success.\n");

    int tot = 0;
    char* p = buf;
    while(1) {
        printf("%s\n", dirp64->name);
        tot += dirp64->len;
        if(tot >= nread) break;
        p += dirp64->len;
        dirp64 = (struct linux_dirent64*)p;
    }
    close(fd);
    TEST_END(__func__);
}

int main(void){
    test_getdents();
    return 0;
}
